﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Core;
using Castle.Windsor;

namespace Adalbertus.BudgetPlanner.Extensions
{
    /// <summary>
    /// Copied from: http://www.iamnotmyself.com/2010/07/31/AnImplementationOfCastleWindsorBootstrapperForCaliburnMicro.aspx
    /// </summary>
    public static class WindsorExtensions
    {
        public static void BuildUp(this IWindsorContainer container, object instance)
        {
            instance.GetType().GetProperties()
                 .Where(property => property.CanWrite && property.PropertyType.IsPublic)
                 .Where(property => container.Kernel.HasComponent(property.PropertyType))
                 .ForEach(property => property.SetValue(instance, container.Resolve(property.PropertyType), null));
        }
    }
}
